<template>
  <dt-modal-edit
    ref="edit"
    title="新建活动"
    :label-width="130"
    :width="600"
    @ok="onOk"
    okText="新建"></dt-modal-edit>
</template>

<script>
  import createActivityOpt from '../opt/create.js'
  import activityMgr from '@/biz/activity/activity'
  import purseMgr from '../purseManage/biz/index.js'

  export default {
    data() {
      return {
        addModel: false,
        formData: {
          activityName: '',
          companyId: [],
          final: 1,
          // port: [],
          shape: 1
        },
        companyList: [],
        info: null
      }
    },

    components: {},

    mounted() {},

    methods: {
      show(info) {
        if (info) {
          let newArr = []
          this.info = info
          info.companyId.split(',').forEach((item) => {
            newArr.push(Number(item))
          })
          this.formData.companyId = newArr
        } else {
          this.formData.companyId = []
        }

        this.$refs.edit.show(createActivityOpt.options(), this.formData)
      },
      hide() {
        this.$refs.edit.hide()
      },
      onOk() {
        console.log(1111, this.formData)
        if (this.info) {
          let params = {
            acId: this.info.acId,
            name: this.formData.activityName,
            companyIds: this.formData.companyId
          }
          purseMgr.copyAcBasics(params).then((res) => {
            this.$Message.success('复制成功')
            setTimeout(() => {
              this.$router.push({
                path: '/marketing/activityDetail',
                query: {
                  acId: res
                }
              })
            }, 1000)
          })
        } else {
          let params = {
            name: this.formData.activityName,
            companyIds: this.formData.companyId
          }
          activityMgr.insertBasics(params).then((res) => {
            this.$router.push({
              path: '/marketing/activityDetail',
              query: {
                acId: res
              }
            })
          })
        }
      }
    }
  }
</script>

<style lang="scss" scoped></style>
